<template>
  <page-header-wrapper>
    <application-search @search="handleSearch" @reset="handleReset"> </application-search>
    <a-card :bordered="false">
      <div class="table-header m-b-24"></div>
      <s-table
        ref="table"
        size="default"
        rowKey="ID"
        :columns="columns"
        :data="loadData"
        :scroll="{ x: true }"
        :pagination="{ showTotal: (total) => `共 ${total} 条` }"
      >
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }} </span>
        <ellipsis :length="26" slot="ellipsis" slot-scope="text">{{ text || '/' }}</ellipsis>
        <span slot="moment" slot-scope="text">{{ text | moment }}</span>
        <div slot="action" slot-scope="text, record">
          <y-button type="link" @click="handleDetail(record.ID)">查看</y-button>
          <a-popconfirm title="确认退出吗？" @confirm="handleConfirm(record)" placement="left">
            <y-button type="link" class="text-warning">退出转补贴</y-button>
          </a-popconfirm>
        </div>
      </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { STable, Ellipsis, buttonSelect, applicationSearch } from '@/components'
import { getAssignmentList, postAssignment } from '@/api/cityReviewAndManage'
export default {
  name: 'cityComplexInquireList',
  components: {
    STable,
    Ellipsis,
    buttonSelect,
    applicationSearch,
  },
  computed: {
    textColor() {
      return function (text) {
        if (text === '') {
          text = '未审批'
        }
        const classMap = new Map([
          ['未审批', 'text-warning'],
          ['不符合', 'text-error'],
          ['符合', 'text-success'],
        ])
        return classMap.get(text)
      }
    },
  },
  data() {
    return {
      queryParam: {
        Mode: 'ExitHousesGetMoney',
        UserID: this.$store.getters.userid,
        strContent: {},
      },
      columns: [
        {
          title: '序号',
          align: 'center',
          fixed: 'left',
          width: '80px',
          scopedSlots: { customRender: 'index' },
        },
        {
          title: '申请编号',
          align: 'center',
          fixed: 'left',
          dataIndex: 'ApplyNO',
        },
        {
          title: '申请人',
          align: 'center',
          fixed: 'left',
          dataIndex: 'Proposer',
        },
        {
          title: '身份证号',
          align: 'center',
          fixed: 'left',
          dataIndex: 'IDCard',
        },
        {
          title: '联系电话',
          align: 'center',
          dataIndex: 'Phone',
        },
        {
          title: '保障方式',
          align: 'center',
          dataIndex: 'ApplyClass',
        },
        {
          title: '补贴方式',
          align: 'center',
          dataIndex: 'CityVfyAssign',
        },
        {
          title: '区域',
          align: 'center',
          dataIndex: 'RegionName',
          scopedSlots: { customRender: 'ellipsis' },
        },
        {
          title: '社区服务中心',
          align: 'center',
          dataIndex: 'TownshipName',
          scopedSlots: { customRender: 'ellipsis' },
        },
        {
          title: '审批结果',
          align: 'center',
          dataIndex: 'CityRfyResult',
          customRender: (text) => <span class={this.textColor(text)}>{text || '未审批'}</span>,
        },
        {
          title: '审批时间',
          align: 'center',
          dataIndex: 'CityRfyDate',
          scopedSlots: { customRender: 'moment' },
        },
        {
          title: '安置信息',
          align: 'center',
          dataIndex: 'EsitesSelect',
          scopedSlots: { customRender: 'ellipsis' },
        },
        {
          title: '安置时间',
          align: 'center',
          dataIndex: 'EsetDate',
          scopedSlots: { customRender: 'moment' },
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'IfQueue',
        },
        {
          title: '退出原因',
          align: 'center',
          dataIndex: 'OldEassign',
        },
        {
          title: '操作',
          align: 'center',
          width: '130px',
          fixed: 'right',
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getAssignmentList(requestParameters).then((res) => res)
      },
    }
  },
  methods: {
    handleSearch(values) {
      this.queryParam.strContent = values
      this.tableRefresh(true)
    },
    handleReset() {
      this.queryParam.strContent = {}
      this.tableRefresh(true)
    },
    tableRefresh(refresh = false) {
      this.$refs.table.refresh(refresh)
    },
    handleDetail(id) {
      localStorage.setItem('browserCacheDetail', JSON.stringify({ id: id }))
      this.$router.push({
        name: 'materialToSubsidyConfirmDetail',
        params: {
          id,
        },
      })
    },
    handleConfirm(record) {
      this.$loading.show({
        tip: '提交中...',
      })
      postAssignment({
        Mode: 'ExitHousesGetMoney',
        UserID: this.$store.getters.userid,
        UserName: this.$store.getters.nickname,
        ProposerID: record.ID,
      })
        .then((res) => {
          this.$message.success('退出成功！')
          this.tableRefresh()
        })
        .finally(() => {
          this.$loading.hide()
        })
    },
  },
}
</script>
<style lang="less" scoped>
/deep/ .ant-table td {
  white-space: nowrap;
}
</style>
